/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package msh.bean;

import java.util.Date;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import mysweethome.entities.Customer;
import mysweethome.sessionbean.CustomerBizLocal;
import org.primefaces.event.FlowEvent;

/**
 *
 * @author BKC
 */
@Named(value="registerBean")
@RequestScoped
public class RegisterBean {
    private String userName;
    private String passWord;
    private String fullName;
    private String email;
    private boolean gender;
    private Date bithDate;
    private String address;
    private String phone;
    private String id;
    private boolean buyer;
    private static final Logger logger = Logger.getLogger(RegisterBean.class.getName());
    @EJB
    private CustomerBizLocal cusBiz;
    /** Creates a new instance of RegisterBean */
    public String Register() {
        boolean result;
        try {
            Customer cus = new Customer();
            id=getCusBiz().GenerateID();
            cus.setUsername(getUserName());
            cus.setAddress(getAddress());
            cus.setBirthdate(getBithDate());
            cus.setEmail(getEmail());
            cus.setFullname(getFullName());
            cus.setGender(isGender());
            cus.setIsBuyer(isBuyer());
            cus.setPhone(getPhone());
            cus.setPassword(getPassWord());
            result = getCusBiz().Register(cus);
            if(result){
                return "registerSuccess";
            }
            else{
                return "registerFail";
            }
        } catch (Exception ex) {
            return "error";
        }
    }
    public String onFlowProcess(FlowEvent event) {  
        //logger.info("Current wizard step:" + event.getOldStep());
        //logger.info("Next step:" + event.getNewStep());
        return event.getNewStep();
    }
    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * @param userName the userName to set
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * @return the passWord
     */
    public String getPassWord() {
        return passWord;
    }

    /**
     * @param passWord the passWord to set
     */
    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }

    /**
     * @return the fullName
     */
    public String getFullName() {
        return fullName;
    }

    /**
     * @param fullName the fullName to set
     */
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the gender
     */
    public boolean isGender() {
        return gender;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(boolean gender) {
        this.gender = gender;
    }

    /**
     * @return the bithDate
     */
    public Date getBithDate() {
        return bithDate;
    }

    /**
     * @param bithDate the bithDate to set
     */
    public void setBithDate(Date bithDate) {
        this.bithDate = bithDate;
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @return the phone
     */
    public String getPhone() {
        return phone;
    }

    /**
     * @param phone the phone to set
     */
    public void setPhone(String phone) {
        this.phone = phone;
    }

    /**
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @return the buyer
     */
    public boolean isBuyer() {
        return buyer;
    }

    /**
     * @param buyer the buyer to set
     */
    public void setBuyer(boolean buyer) {
        this.buyer = buyer;
    }

    /**
     * @return the cusBiz
     */
    public CustomerBizLocal getCusBiz() {
        return cusBiz;
    }

    /**
     * @param cusBiz the cusBiz to set
     */
    public void setCusBiz(CustomerBizLocal cusBiz) {
        this.cusBiz = cusBiz;
    }


}
